class Vector:
    """
        向量
    """

    def __init__(self, x):
        self.x = x

    def __add__(self, other):
        return Vector(self.x + other)

    def __radd__(self, other):
        return Vector(self.x + other)

    def __sub__(self, other):
        return Vector(self.x - other)

    def __rsub__(self, other):
        return Vector(self.x - other)

    def __mul__(self, other):
        return Vector(self.x * other)

    def __rmul__(self, other):
        return Vector(self.x * other)

    def __str__(self):
        return '向量的x变量是：%s' % self.x

    def __repr__(self):
        return "Vector(%d)" % self.x

    def __isub__(self, other):
        """
            重载复合运算符，避免创建新对象出来
        :param other:
        :return:
        """
        self.x -= other
        return self

    def __imul__(self, other):
        self.x *= other
        return self

    def __lt__(self, other):
        return self.x < other


v01 = Vector(10)
print(v01 + 5)
v02 = v01 + 5
print(v01 - 5)
print(v01 * 10)

print(1 + v01)

v04 = v01 + v02
print(v04)

v05 = 10 - v01
v06 = 10 * v01
print(v05)
print(v06)
v07 = v05 * v06
v08 = v06 - v05
print(v07.x)
print(v08.x)

print(v06)
print(id(v06))
# v06 += 1  会创建新对象，以为没有重载方法
v06 -= 1
print(v06)
print(id(v06))
